package cn.tedu.charging.order.repository.impl;

import cn.tedu.charging.common.pojo.po.ChargingBillFailPO;
import cn.tedu.charging.common.pojo.po.ChargingBillSuccessPO;
import cn.tedu.charging.order.mapper.BillFailMapper;
import cn.tedu.charging.order.mapper.BillSuccessMapper;
import cn.tedu.charging.order.repository.BillRepository;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class BillRepositoryImpl implements BillRepository {
    @Autowired
    private BillSuccessMapper billSuccessMapper;
    @Autowired
    private BillFailMapper billFailMapper;

    @Override
    public void saveSuccessBill(ChargingBillSuccessPO po) {
        billSuccessMapper.insert(po);
    }

    @Override
    public void saveFailBill(ChargingBillFailPO po) {
        billFailMapper.insert(po);
    }

    @Override
    public Boolean checkSuccessOrFail(String orderNo) {
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        //select count() from charging_bill_success where bill_id=
        Long suc = billSuccessMapper.selectCount(queryWrapper);
        //select count() from charging_bill_fail where bill_id=
        Long fail = billFailMapper.selectCount(queryWrapper);
        //判断是否都不存在
        return suc>0||fail>0;
    }
}
